# 作业1：
# url：http://www.bjhospital.net/
# 用例1：
# 搜索骨科—>点击搜索—>点击出来的第一个链接—>断言文本内
"""
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
driver=webdriver.Chrome() # 初始化driver
driver.get("http://www.bjhospital.net/")
driver.maximize_window()
driver.implicitly_wait(15)

# 输入内容
driver.find_element(By.CLASS_NAME,'keyword').send_keys('骨科')
#点击搜索
driver.find_elements(By.CLASS_NAME,"btn")[0].click()
#点击第一个链接
# driver.find_elements(By.TAG_NAME,'a')[0].click()
driver.find_elements(By.XPATH,"//*[@target='_blank']")[0].click()
# 句柄切换
driver.switch_to.window(driver.window_handles[-1])
# 断言信息
text = driver.find_element(By.XPATH,"/html/body/div[3]/div/div/article/h1").text
assert text == "毕节市第一人民医院高值医用耗材网上阳光平台议价意向公开"
"""
# crmeb，登录，新增用户分组、删除用户分组
import time
from selenium import webdriver
import uuid
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from loctor import *
class CRMEB:
    uuid_ = str(uuid.uuid4()).split('-')[0]  # 类属性
    def __init__(self,driver):
        self.driver = driver
        self.driver.maximize_window()
        # self.driver.implicitly_wait(15)
    def open_url(self,url):
        """
        :param url: 传入要打开的url
        :return:
        """
        self.driver.get(url)
    def input_user(self,user:str):
        # 账号
        WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located(input_user_elemnt)).send_keys(user)
        # self.driver.find_element(*input_user_elemnt).send_keys(user)
    def input_password(self,password:str):
        # 密码
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located(input_password_element)).send_keys(password)
        # self.driver.find_element(*input_password_element).send_keys(password)
    def click_login_btn(self):
        # 点击登录
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located(click_login_btn_element)).click()
        # self.driver.find_element(*click_login_btn_element).click()
    def click_user_group_btn(self):
        # 点击用户
        time.sleep(2)  # 等待页面跳转
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(click_user_group_btn_element1))[1].click()
        # self.driver.find_elements(*click_user_group_btn_element1)[1].click()
        # 点击用户分组
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located(click_user_group_btn_element2)).click()
        # self.driver.find_element(*click_user_group_btn_element2).click()
    def click_add_user_group(self):
        # 点击添加分组
        # self.driver.find_element(*click_add_user_group_element).click()
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located(click_add_user_group_element)).click()
    def input_user_group(self,text:str):
        time.sleep(2)  # 等待弹窗弹出
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located(input_user_group_element)).send_keys(text + self.uuid_)
        # self.driver.find_element(*input_user_group_element).send_keys(text + self.uuid_)
    def click_ok(self):
        # 点击确认
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(click_ok_element))[2].click()
        # self.driver.find_elements(*click_ok_element)[2].click()
    def assert_text(self,text:str):
        time.sleep(3)
        # spans = self.driver.find_elements(*assert_text_element)
        spans = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_all_elements_located(assert_text_element))
        # 遍历
        for i in spans:
            # 如果某一个是
            if i.text == text + self.uuid_:
                # 找到它
                assert i.text == text + self.uuid_
    def click_delete_btn(self):
        time.sleep(2)
        # self.driver.find_elements(*click_delete_btn_element)[-1].click()
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(click_delete_btn_element))[-1].click()
    def click_alert_ok(self):
        time.sleep(3)
        # self.driver.find_elements(*click_alert_ok_element)[2].click()
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(click_alert_ok_element))[2].click()

if __name__ == '__main__':
    services = Service('chromedriver.exe')
    driver1 = webdriver.Chrome(service=services)
    driver = CRMEB(driver1)
    driver.open_url("http://47.98.51.162:8899/admin/login")
    driver.input_user("admin")
    driver.input_password("Aa123456!")
    driver.click_login_btn()
    driver.click_user_group_btn()
    driver.click_add_user_group()
    driver.input_user_group("金巴")
    driver.click_ok()
    driver.assert_text("金巴")
    driver.click_delete_btn()
    driver.click_alert_ok()

    # print(input_user_elemnt)






